"""
诺基亚N85页面
操作方法
"""
from common.base import Base, get_driver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys


class N85Page(Base):
    # 购买数量
    def send_keys_number(self, number):
        # 定位输入框
        kw = self.find_element((By.ID, "number"))
        kw.send_keys(Keys.CONTROL, "a")
        kw.send_keys(number)

    # 点击蓝牙耳机
    def click_bluetooth_headset(self):
        self.click((By.ID, "spec_value_158"))

    # 点击数据线
    def click_usb_cable(self):
        self.click((By.ID, "spec_value_159"))

    # 点击线控耳机
    def click_wired_headset(self):
        self.click((By.ID, "spec_value_157"))

    # 点击颜色黑色
    def click_black(self):
        self.click((By.ID, "spec_value_163"))

    # 点击立即购买
    def click_buy(self):
        self.click((By.XPATH, "//img[@src='themes/default/images/buybtn1.png']"))


if __name__ == '__main__':
    # 创建浏览器驱动
    driver = get_driver()
    n85 = N85Page(driver)
    # 访问目标网址
    n85.get('http://localhost:8080/ecshop/goods.php?id=32')
    n85.send_keys_number(2)
    n85.click_bluetooth_headset()
    n85.click_usb_cable()
    n85.click_wired_headset()
    n85.click_black()
    n85.click_buy()
    n85.quit(2)

